package com.hxc.shop.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * swagger配置类
 *
 * @author zxj
 * @date 2019/5/22 10:41
 */
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

  @Bean
  public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .pathMapping("/")
            .enable(true)
            .host("localhost:9000")
            .select()
            //这里指定Controller扫描包路径(项目路径也行)
            .apis(RequestHandlerSelectors.basePackage("com.hxc.shop.controller"))
            .paths(PathSelectors.any())
            .build()
            .apiInfo(apiInfo());
  }

  private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
            .title("购物商城接口文档")
            .description("购物商城接口文档描述")
            .contact(new Contact("相与还","http://localhost:9000/shopBack/doc.html","a1947934569@163.com"))
            .termsOfServiceUrl("http://localhost:9000/shopBack/doc.html")
            .version("1.0.0")
            .build();
  }
}
